﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace _07_控件
{
    /// <summary>
    /// _11_ListBox.xaml 的交互逻辑
    /// </summary>
    public partial class _11_ListBox : Window
    {
        public _11_ListBox()
        {
            InitializeComponent();
            List<_11_ListInfos> list = new List<_11_ListInfos>()
            {
                new _11_ListInfos() {ProductId=0,ProductName="牛奶" },
                new _11_ListInfos(){ProductId=1,ProductName="蔬菜"}
            };
            this.listTwo.ItemsSource = list;//设置数据源
        }

        private void listTwo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (listTwo.SelectedItem != null)
            {
                _11_ListInfos _11_ListInfos = (_11_ListInfos)listTwo.SelectedItem;
                MessageBox.Show(_11_ListInfos.ProductName);
            }
        }
    }
}
